package com.itheima.service.impl;

import com.itheima.dao.RoleDao;
import com.itheima.domain.Permission;
import com.itheima.domain.Role;
import com.itheima.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ClassName:RoleServiceImpl
 * Package:com.itheima.service.impl
 * Description:
 * Date:2020/3/12 15:09
 * User: snow
 */
@Service("roleService")
@Transactional
public class RoleServiceImpl implements RoleService {


	@Autowired
	private RoleDao roleDao;

	@Override
	public List<Role> findAll() throws Exception {
		return roleDao.findAll();
	}

	@Override
	public void save(Role role) throws Exception {
		roleDao.save(role);
	}

	/**
	 *查找角色
	 * @param roleId
	 * @return
	 * @throws Exception
	 */
	@Override
	public Role findById(String roleId) throws Exception {
		return roleDao.findById(roleId);
	}

	/**
	 * 查找角色可添加权限
	 * @param roleId
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Permission> findOtherPermission(String roleId) throws Exception {
		return roleDao.findOtherPermission(roleId);
	}

	/**
	 * 角色添加权限
	 * @param roleId
	 * @param permissionIds
	 * @throws Exception
	 */
	@Override
	public void addPermissionToRole(String roleId, String[] permissionIds) throws Exception {
		for (String permissionId : permissionIds) {
			roleDao.addPermissionToRole(roleId,permissionId);
		}
	}
}
